from django.db import models
from django.contrib.auth.models import AbstractUser


class ModelBase(models.Model):
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        # 为抽象模型类，用于其他模型来继承，数据库迁移时不会创建ModelBase表
        abstract = True


class User(ModelBase):
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=30, unique=True)
    password = models.CharField(max_length=30)
    email = models.EmailField()

    class Meta:
        ordering = ['-update_time', '-id']

    def __str__(self):
        return f'User<id={self.id},username={self.username},email={self.email}'
